<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#div4{
				width: 500px;
				height: 500px;
				background-color: red;
				justify-content: center;
				align-items: center;display: -webkit-flex;
			}
			#div3{
				width: 400px;
				height: 400px;
				background-color: orange;
				justify-content: center;
				align-items: center;display: -webkit-flex;
			}
			#div2{
				width: 300px;
				height: 300px;
				background-color:green;
				justify-content: center;
				align-items: center;display: -webkit-flex;
			}
			#div1{
				width: 200px;
				height: 200px;
				background-color: blue;
				
				justify-content: center;
				align-items: center;display: -webkit-flex;
			}
		</style>
	</head>
	<body>
		<!-- 4.制作4个嵌套DIV ，要求：
		      1.每个父DIV尺寸必须大于子DIV
		      2.实现每个DIV在父DIV正中间
		      3.每个DIV至少要包含一个非DIV元素，比如：文字，P标签，A标签，图片等
		      4.通过最底层DIV，打印每层父DIV，如：
			1级父元素为（），1级父节点为（）
			2级父元素为（），2级父节点为（）
			....
		      5.查找每个DIV的子元素和子对象 -->
			  <div id="div4" align="center" >
			  	<br>
				<div id="div3" align="center">
					<img src="./QQ图片20211023153520.jpg" width="20px" height="20px">
					<div id="div2" align="center">
						<a href="https://www.baidu.com">百度</a>
						<div id="div1" align="center">
					<p>哈喽</p>
						</div>	
					</div>	
				</div>
			  </div>
			  <button type="button" onclick="father();">打印每层父DIV</button>
			  <button type="button" onclick="abcd();">查找每个DIV的子元素和子对象</button>
	</body>
	<script type="text/javascript">
		function father(){
			console.log('1级父元素为');
			console.log(document.getElementById('div1').parentElement);
			console.log('1级父节点为');
			console.log(document.getElementById('div1').parentNode);
			console.log('2级父元素为');
			console.log(document.getElementById('div1').parentElement.parentElement);
			console.log('2级父节点为');
			console.log(document.getElementById('div1').parentNode.parentNode);
			console.log('3级父元素为');
			console.log(document.getElementById('div1').parentElement.parentElement.parentElement);
			console.log('3级父节点为');
			console.log(document.getElementById('div1').parentNode.parentNode.parentNode);
			console.log('4级父元素为');
			console.log(document.getElementById('div1').parentElement.parentElement.parentElement.parentElement);
			console.log('4级父节点为');
			console.log(document.getElementById('div1').parentNode.parentNode.parentNode.parentNode);
		}
		function abcd(){
			console.log('div4的子元素为');
			console.log(document.getElementById('div4').children);
			console.log('div4子节点为');
			console.log(document.getElementById('div4').childNodes);
			console.log('div3的子元素为');
			console.log(document.getElementById('div3').children);
			console.log('div3子节点为');
			console.log(document.getElementById('div3').childNodes);
			console.log('div2的子元素为');
			console.log(document.getElementById('div2').children);
			console.log('div2子节点为');
			console.log(document.getElementById('div2').childNodes);
			console.log('div1的子元素为');
			console.log(document.getElementById('div1').children);
			console.log('div1子节点为');
			console.log(document.getElementById('div1').childNodes);
		}
	</script>
</html>
